<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Plugins
 *
 * @author Royan
 */
class Plugins {
    //put your code here
    static public $config;
    static function findPlugin( $target )
    {
        $pluginsSource = self::$config->__get("plugins");
        $pluginsCount = count( $pluginsSource );

        FOR ( $i = 0; $i < $pluginsCount; $i++ )
        {
            IF( (string)$pluginsSource[$i]->target === $target )
            {
                IF ( file_exists( PATH_SITE.(string)$pluginsSource[$i]->classPath ) )
                {
                    require_once PATH_INTERFACES."IPlugin.interface.php";
                    require_once PATH_SITE.$pluginsSource[$i]->classPath;
                    $pluginClass = (string)$pluginsSource[$i]->class;

                    IF ( class_exists( $pluginClass ) )
                    {
                        IF ( in_array( "excute", get_class_methods( $pluginClass ) ) )
                        {
                            RETURN $pluginClass;
                        }
                        ELSE{
                            Logger::trace( "excute does not exist" );
                        }
                    }ELSE{
                        Logger::trace( $pluginClass." does not exist" );
                    }
                }
                ELSE
                {
                    Logger::trace( (string)$pluginsSource[$i]->classPath." does not exist" );
                }
            }
        }
        RETURN FALSE;
    }
}

?>
